﻿using System;
using System.Text;
using jQueryCSharp.Extensions;

namespace jQueryCSharp.ui
{
    public class Accordion : jQueryCSharpBase
    {
        #region Constantes
        private const bool DISABLED = false;
        private const string ACTIVE = "first child";
        private const string ANIMATED = "slide";
        private const bool AUTOHEIGHT = true;
        private const bool CLEARSTYLE = false;
        private const bool COLLAPSIBLE = false;
        private const string EVENT = "click";
        private const bool FILLSPACE = false;
        private const string HEADER = "> li > :first-child,> :not(li):even";
        private const string ICONS = "'header': 'ui-icon-triangle-1-e', 'headerSelected': 'ui-icon-triangle-1-s'}";
        private const bool NAVIGATION = false;
        private const string NAVIGATIONFILTER = "";
        #endregion

        /// <summary>
        /// Construtor
        /// </summary>
        public Accordion( )
            : this( "" )
        {

        }

        /// <summary>
        /// Construtor
        /// </summary>
        public Accordion( string identifier )
        {
            Disabled = DISABLED;
            Active = ACTIVE;
            Animated = ANIMATED;
            AutoHeight = AUTOHEIGHT;
            ClearStyle = CLEARSTYLE;
            Collapsible = COLLAPSIBLE;
            Event = EVENT;
            FillSpace = FILLSPACE;
            Header = HEADER;
            Icons = ICONS;
            Navigation = NAVIGATION;
            NavigationFilter = NAVIGATIONFILTER;

            if ( !String.IsNullOrEmpty( identifier ) )
            {
                if ( identifier.Contains( "#" ) )
                {
                    ID = identifier.Replace( "#", "" );
                }
                else
                {
                    Class = identifier.Replace( ".", "" );
                }
            }
        }

        #region Propriedades
        public bool Disabled { get; set; }
        public string Active { get; set; }
        public string Animated { get; set; }
        public bool AutoHeight { get; set; }
        public bool ClearStyle { get; set; }
        public bool Collapsible { get; set; }
        public string Event { get; set; }
        public bool FillSpace { get; set; }
        public string Header { get; set; }
        public string Icons { get; set; }
        public bool Navigation { get; set; }
        public string NavigationFilter { get; set; }
        #endregion

        public override string ToString( )
        {
            var sb = new StringBuilder( );

            if ( Disabled != DISABLED )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "disabled", Disabled.ToString( ).ToLower( ) ) );
            }

            if ( Active != ACTIVE )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "active", Active ) );
            }

            if ( Animated != ANIMATED )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "animated", "'{0}'".Formatar( Animated ) ) );
            }

            if ( AutoHeight != AUTOHEIGHT )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "autoHeight", AutoHeight.ToString( ).ToLower( ) ) );
            }

            if ( ClearStyle != CLEARSTYLE )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "clearStyle", ClearStyle.ToString( ).ToLower( ) ) );
            }

            if ( Collapsible != COLLAPSIBLE )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "collapsible", Collapsible.ToString( ).ToLower( ) ) );
            }

            if ( Event != EVENT )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "event", "'{0}'".Formatar( Event ) ) );
            }

            if ( FillSpace != FILLSPACE )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "fillSpace", FillSpace.ToString( ).ToLower( ) ) );
            }

            if ( Header != HEADER )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "header", "'{0}'".Formatar( Header ) ) );
            }

            if ( Icons != ICONS )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "icons", "'{0}'".Formatar( Icons ) ) );
            }

            if ( Navigation != NAVIGATION )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "navigation", Navigation.ToString( ).ToLower( ) ) );
            }

            if ( NavigationFilter != NAVIGATIONFILTER )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "navigationFilter", "'{0}'".Formatar( NavigationFilter ) ) );
            }


            if ( sb.Length > 0 )
            {
                return String.Concat( "{", sb.ToString( ), "}" );
            }

            return sb.ToString( );
        }
    }
}
